package com.cdks.wuxiu.api.service.mysql;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdks.wuxiu.api.component.constant.Constant;
import com.cdks.wuxiu.api.mapper.UserBlockInfoMapper;
import com.cdks.wuxiu.entity.mysql.UserBaseInfo;
import com.cdks.wuxiu.entity.mysql.UserBlockInfo;

import java.util.List;

import org.springframework.stereotype.Service;


/**
 * 用户屏蔽信息 服务实现类
 */
@Service
public class UserBlockInfoServiceImpl extends ServiceImpl<UserBlockInfoMapper, UserBlockInfo> implements UserBlockInfoService {
    @Override
    public int block(long userId, long destId) {
        UserBlockInfo info  = new UserBlockInfo();
        info.setUserId(userId);
        info.setDestId(destId);

        baseMapper.insert(info);

        return 0;
    }

    @Override
    public int cancel(long userId, long destId) {
        QueryWrapper<UserBlockInfo> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(UserBlockInfo::getDestId, destId)
                        .eq(UserBlockInfo::getUserId, userId);
        baseMapper.delete(wrapper);

        return 0;
    }

    @Override
    public List<UserBaseInfo> getBlockList(long userId, int page) {
        return baseMapper.getBlockList(userId, page * Constant.LIST_PAGE_SIZE, Constant.LIST_PAGE_SIZE);
    }

    @Override
    public UserBlockInfo getBlockedInfo(long userId, long destId) {
        QueryWrapper<UserBlockInfo> wrapper;
        
        wrapper  = new QueryWrapper<>();
        wrapper.lambda().eq(UserBlockInfo::getUserId, userId)
                        .eq(UserBlockInfo::getDestId, destId);

        return baseMapper.selectOne(wrapper);
    }
}
